﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class login : System.Web.UI.Page
{
    protected void  Page_Load(object sender, EventArgs e)
    {
        string username = Request.QueryString["username"].ToString().Trim();
        string password = Request.QueryString["password"].ToString().Trim();
        //根据用户名长度判断用户类型
        if (username.Length == 6)
        {
            string sql = "select count(*) from tb_admin where admin_id = '" + username + "' and admin_pwd ='" + password + "'";
            object i =SqlServer.ExecuteScalar(sql);
            if (i.ToString() == "1")
            {
                Session["admin_id"] = username;
                Session["admin_password"] = password;
                Response.Write("1");
            }
            else
            {
                Response.Write("0");
            }
            
            
        }
        else if (username.Length == 10)
        {
            //教师
            string sql = "select count(*) from tb_teacher where teacher_id = '" + username + "' and teacher_pwd ='" + password + "'";
            object i = SqlServer.ExecuteScalar(sql);
            if (i.ToString() == "1")
            {
                Session["teacher_id"] = username;
                Session["teacher_password"] = password;
                Response.Write("2");
            }
            else
            {
                Response.Write("0");
            }
        }
        else
        {
            //学生
            string sql = "select count(*) from tb_student where student_id = '" + username + "' and student_pwd ='" + password + "'";
            object i = SqlServer.ExecuteScalar(sql);
            if (i.ToString() == "1")
            {
                Session["student_id"] = username;
                Session["student_password"] = password;
                Response.Write("3");
            }
            else
            {
                Response.Write("0");
            }
        }

        Response.End();
        return;
    }
}